﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using DDD.Core;

namespace DDD.OpenTK {
    /// <summary>
    /// <see cref="DDD.Core.PolygonMode"/>を拡張するクラス
    /// </summary>
    public static class PolygonModeExtensions {
        /// <summary>
        /// コンパイルします
        /// </summary>
        /// <param name="pmode"><see cref="DDD.Core.PolygonMode"/>オブジェクト</param>
        public static void Compile (this DDD.Core.PolygonMode pmode) {
            // Do nothing.
        }

        /// <summary>
        /// レンダリングします
        /// </summary>
        /// <param name="pmode"><see cref="DDD.Core.PolygonMode"/>オブジェクト</param>
        public static void Render (this DDD.Core.PolygonMode pmode) {

            GL.LineWidth (pmode.LineWidth);
            GL.Enable (EnableCap.CullFace);

            switch (pmode.Culling) {
                case CullingMode.None: GL.Disable (EnableCap.CullFace); ; break;
                case CullingMode.Back: GL.CullFace (CullFaceMode.Back); break;
                case CullingMode.Front: GL.CullFace (CullFaceMode.Front); break;
                case CullingMode.FrontAndBack: GL.CullFace (CullFaceMode.FrontAndBack); break;
                default: throw new NotImplementedException ("Sorry");
            }

            switch (pmode.Winding) {
                case WindingMode.CCW: GL.FrontFace (FrontFaceDirection.Ccw); break;
                case WindingMode.CW: GL.FrontFace (FrontFaceDirection.Cw);  break;
                default: throw new NotImplementedException ("Sorry");
            }


        }

    }
}
